﻿using Microsoft.AspNetCore.Mvc;
using ServiceCore.Entity.Core;
using ServiceCore.Entity.Model;
using ServiceCore.Entity.Param.Tag;
using ServiceCore.Service;
using ServiceCore.WebApi.jwt;

namespace ServiceCore.WebApi.Controllers
{
    /// <summary>
    /// 标签类型
    /// </summary>
    [Route("Api/[controller]/[action]")]
    [ApiController]
    public class TagTypeController : ApiJwtController
    {
        private TagTypeService tagTypeService = new TagTypeService();

        /// <summary>
        /// 列表
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<TagTypeInfo, List<TagTypeInfo>> List(BaseParam<TagTypeInfo, List<TagTypeInfo>> arg)
        {
            arg = tagTypeService.TagType_List(arg);

            return arg;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<TagTypeInfo, long> Add(BaseParam<TagTypeInfo, long> arg)
        {
            var userInfo = GetJwtUserInfo();
            arg.Param.CreateUserId = userInfo.Id;
            arg = tagTypeService.TagType_Add(arg);

            return arg;
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<TagTypeInfo, long> Edit(BaseParam<TagTypeInfo, long> arg)
        {
            arg = tagTypeService.TagType_Edit(arg);

            return arg;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<TagDeleteParam, long> Del(BaseParam<TagDeleteParam, long> arg)
        {
            arg = tagTypeService.TagType_Delete(arg);

            return arg;
        }

        /// <summary>
        /// 数据初始化
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<string, string> InitData()
        {
            var result = new BaseParam<string, string>();
            var user = GetJwtUserInfo();
            if (user == null)
            {
                result.ErrorMsg = "请先登录";
                return result;
            }
            if (user.IsAdmin != 1)
            {
                result.ErrorMsg = "权限不足";
                return result;
            }

            var data = tagTypeService.InitDataStr;
            return tagTypeService.InitData(data);
        }
    }
}
